$(document).ready(function() {
	$('a[rel="external"]').attr('target', '_blank');
/* 	var h =($(window).height() - $('.wd-login-content').outerHeight())/2;
	$('#wd-wrapper').css("padding-top", h); */
	var h1 = $('body').height();
	var h2 = $(window).height();
	if(h1>h2){
		$(document).scroll(function() {
			$('.wd-fixed').css('position','fixed');
		});
	};
	$('#wd-header-line').hide();
	$('.wd-bt-dropdown a').click(function(){
		var i = $('.wd-bt-dropdown').hasClass('wd-bt-dropdown-active');
		if(!i){			
			$(this).parent().animate({top:'87px'},{queue:false,duration:400});
			$('#wd-header-line').slideDown();
			$('.wd-shortcut').fadeIn();
			$(this).parent().addClass('wd-bt-dropdown-active');
			$('.wd-fixed').height(91);
			$('body').css("margin-top","91px");
		}
		else{
			$(this).parent().animate({top:'52px'},{queue:false,duration:400});	
			$('#wd-header-line').slideUp();
			$('.wd-shortcut').fadeOut();
			$(this).parent().removeClass('wd-bt-dropdown-active');
			$('.wd-fixed').height(52);
			$('body').css("margin-top","52px");
		}
		return false;
	});	
	//Form Search
	$('.go').click(function(){
		if($('.wd-form-search').is(':hidden')){
			$('.wd-form-search').slideDown('slow');
		}
		else{
			$('.wd-form-search').slideUp('slow');
		}
		return false;
	});
	$(document).bind('click',function(){
		$('.wd-form-search').slideUp('slow');
	});
	 $('.wd-form-search').click(function(e) {
          e.stopPropagation();
    });
	$('.wd-close-form').click(function(){
		$('.wd-form-search').slideUp('slow');
		return false;
	}); 
	//Tab
	$('.wd-tab').each(function(){
		$(this).find('.wd-section').hide();

		var current = $(this).find('.wd-item').children('.wd-current');
		if (current.length == 0){
			$(this).find('.wd-item').children(':first-child').addClass('wd-current');
			$($(this).find('.wd-item').children(':first-child').find('a').attr('href')).show();
		}

		$(this).find('.wd-item').find('a').click(function(){
			var current = $(this).parent().hasClass('wd-current');
			if (current == false){
				$(this).parent()
					.addClass('wd-current')
					.siblings().each(function(){
						$(this).removeClass('wd-current');
						$($(this).find('a').attr('href')).hide();
					});
				$($(this).attr('href')).fadeIn();
			}
			return false;
		});
	});
	var wid = $('.wd-current a').width();
	var wid2 = wid/2+35;  			
	$('.wd-arrow-extra').css('left', wid2);
	//Accordion add
	$('.wd-arrow').click(function(){
		$(this).parent().siblings('.rowset').slideToggle('slows');
		$(this).toggleClass('wd-arrow-active');
		$(this).parent().toggleClass('wd-none-margin');
	});
	 jQuery('#mega-menu').dcMegaMenu({
		rowItems: '4',
		speed: 'fast',
        effect: 'slide'
	 });
	//Button		
		$( ".control-icon button:first" ).button({
            icons: {
                primary: "icon-add"
            }           
        }).next().button({
            icons: {
                primary: "icon-copy"
            }
        }).next().button({
            icons: {
                primary: "icon-edit"
                //secondary: "ui-icon-triangle-1-s"
            }
        }).next().button({
            icons: {
                primary: "icon-remove"
            }
        });
		$( "#filter-toggle" ).button({
			 icons: {
                primary: "ui-icon-wrench"
            }
		});
		$( "#refresh" ).button({
			 icons: {
                primary: "ui-icon-refresh"
            },
			text:false
		});
		$('#wd-setting').button({
			icons: {
				primary: "icon-setting",
				secondary: "icon-dropdown"
			},
			text:false
		});
		$('.wd-none-border').removeClass('ui-corner-all');
		$('.wd-all-message').button({
            icons: {                
                secondary: "ui-icon-triangle-2-n-s"
            }
		});
		$('.wd-bt-estimate').button({
            icons: {                
                secondary: "ui-icon-triangle-2-n-s"
            }
		});
});		